const express=require('express')
const path=require('path')
const app=express()
app.use(express.json())
app.use(express.urlencoded())
const data=[{
    name:'魈',
    age:'18',
    sex:'男'
}]
app.post('/adduser', (req,res) => {
    const { name, age, sex } = req.body
    if (!name || !age || !sex) {
        return res.send({
            code: 10001,
            mes: "添加失败",
            data: null
        })
    }
    res.send({
        code: 10000,
        mes: "添加成功",
        data: {
            name,
            age,
            sex
        }
    })
    data.push(req.body)
    console.log(data);
})
app.get('/1',(req,res)=>{
   const filePath=path.resolve(__dirname,'index.html')
   res.sendFile(filePath)
})
app.listen(9000,()=>{
    console.log('服务器部署成功，网址为http://127.0.0.1:9000');
})